namespace SubSonic
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    [Serializable]
    internal class ListComparer<ItemType> : Comparer<ItemType> where ItemType: AbstractRecord<ItemType>, new()
    {
        private bool ascending;
        private string columnName;
        private DbType dbType;

        public ListComparer()
        {
            this.dbType = DbType.String;
        }

        public override int Compare(ItemType x, ItemType y)
        {
            int num;
            object columnValue = x.GetColumnValue<object>(this.columnName);
            object obj3 = y.GetColumnValue<object>(this.columnName);
            if ((this.dbType == DbType.String) || (this.dbType == DbType.Guid))
            {
                string str = columnValue.ToString();
                string strB = obj3.ToString();
                num = str.CompareTo(strB);
            }
            else if (this.dbType == DbType.DateTime)
            {
                DateTime time = Convert.ToDateTime(columnValue);
                DateTime time2 = Convert.ToDateTime(obj3);
                num = time.CompareTo(time2);
            }
            else if (this.dbType == DbType.Boolean)
            {
                bool flag = Convert.ToBoolean(columnValue);
                bool flag2 = Convert.ToBoolean(obj3);
                num = flag.CompareTo(flag2);
            }
            else
            {
                double num2 = Convert.ToDouble(columnValue);
                double num3 = Convert.ToDouble(obj3);
                num = num2.CompareTo(num3);
            }
            if (!this.ascending)
            {
                num *= -1;
            }
            return num;
        }

        public bool Ascending
        {
            get
            {
                return this.ascending;
            }
            set
            {
                this.ascending = value;
            }
        }

        public string ColumnName
        {
            get
            {
                return this.columnName;
            }
            set
            {
                this.columnName = value;
            }
        }

        public DbType DBType
        {
            get
            {
                return this.dbType;
            }
            set
            {
                this.dbType = value;
            }
        }
    }
}

